package at.ac.univie.zsu.aguataplan.video.util;

import org.apache.log4j.Logger;

import at.ac.univie.zsu.aguataplan.exception.FtpHandlingException;
import at.ac.univie.zsu.aguataplan.util.Constants;
import at.ac.univie.zsu.aguataplan.video.IVideoService;

/**
 * @author gerry
 * 
 */
public class ThreadFtp extends ThreadWorking implements Constants {
	private static Logger log = Logger.getLogger(ThreadFtp.class);

	private FtpHandling fh;

	private IVideoService iVideoService;

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public ThreadFtp(IVideoService iVideoService, String dirInput, String fileInput, String dirOutput,
			String fileOutput, String server, int port, String username, String password) {
		super(dirInput, fileInput, dirOutput, fileOutput);

		this.iVideoService = iVideoService;

		fh = new FtpHandling(iVideoService, server, port, username, password);
	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public void run() {
		try {
			fh.upload(dirInput, fileInput, dirOutput, fileOutput);
		} catch (FtpHandlingException e) {
			log.error(e.toString());
			this.retValue = e.getStatus();
		}
	}

	public int delFile() {
		this.retValue = RET_OK;
		try {
			// ????????????????????
			// fh.delete(dirInput, fileInput);
			fh.delete(dirOutput, fileOutput);
		} catch (FtpHandlingException e) {
			log.error(e.toString());
			this.retValue = e.getStatus();
		}
		return this.retValue;
	}
}
